***************************
***** MAIN MANUSCRIPT *****
***************************

use "COVID19_TRAC.dta", clear

* ssc install estout, replace

* Table 1: Category 1 Entry Restrictions * 

stset date, id (cowcode) failure (be_cat_1_China_carryover)
stsum

eststo clear 
eststo: stcox contract_workers_abroad_2018_pc migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc, nohr vce(robust)
eststo: stcox labor_services_workers_2018_pc migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc, nohr vce(robust)
eststo: stcox intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc, nohr vce(robust)
eststo: stcox contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc, nohr vce(robust)
eststo: stcox contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china fdi_china_inward_pc_2018 trade_china_gdp_2018 deaths_7_day_pc, nohr vce(robust)
eststo: stcox contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china fdi_china_inward_pc_2018 trade_china_gdp_2018 trade_nonchina_gdp_2018 deaths_7_day_pc, nohr vce(robust)

esttab using "Table1.tex", label keep(contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 fdi_china_inward_pc_2018 log_gdp log_gdp_pc trade_china_gdp_2018 trade_nonchina_gdp_2018 log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc) order(contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 fdi_china_inward_pc_2018 log_gdp log_gdp_pc trade_china_gdp_2018 trade_nonchina_gdp_2018 log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc) nonotes se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) compress nogaps nodepvars mtitles("" "" "" "" "" "") 

* Table 2: Any Category 1 Restrictions

stset date, id (cowcode) failure (be_any_1_China_carryover)
stsum

eststo clear 
eststo: stcox contract_workers_abroad_2018_pc migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc, nohr vce(robust)
eststo: stcox labor_services_workers_2018_pc migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc, nohr vce(robust)
eststo: stcox intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc, nohr vce(robust)
eststo: stcox contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc, nohr vce(robust)
eststo: stcox contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china fdi_china_inward_pc_2018 trade_china_gdp_2018 deaths_7_day_pc, nohr vce(robust)
eststo: stcox contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china fdi_china_inward_pc_2018 trade_china_gdp_2018 trade_nonchina_gdp_2018 deaths_7_day_pc, nohr vce(robust)

esttab using "Table2.tex", label keep(contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 fdi_china_inward_pc_2018 log_gdp log_gdp_pc trade_china_gdp_2018 trade_nonchina_gdp_2018 log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc) order(contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 fdi_china_inward_pc_2018 log_gdp log_gdp_pc trade_china_gdp_2018 trade_nonchina_gdp_2018 log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc) nonotes se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) compress nogaps nodepvars mtitles("" "" "" "" "" "") 

* Figure 3: Targeted Entry Restrictions against China by Date

drop if date > 22000 | date < 21930
replace be_cat_1_China = 1 if bf_cat_1_China == 1 & bna_cat_1_China == 1
collapse(sum) be_cat_1_China be_cat_2_China be_cat_3_China, by(date)
gen China_1 = be_cat_1_China
gen China_1_2 = be_cat_1_China + be_cat_2_China
gen China_1_3 = be_cat_1_China + be_cat_2_China + be_cat_3_China

twoway bar China_1 date, bcolor("127 0 0") || rbar China_1 China_1_2  date, bcolor("239 101 72") || rbar China_1_2 China_1_3 date, bcolor("253 187 132")||,   ytitle("Countries Introducing Restrictions", size(4))  yscale(titlegap(*5)) xscale(titlegap(*5)) xtitle("Date of Implementation", size(4))  legend (region(lcolor(white)) cols(3) lab(1 "Catogery 1") lab(2 "Category 2") lab(3 "Category 3") size(3)) plotregion(fcolor(white) lstyle(none) lcolor(white)) graphregion(fcolor(white) lstyle(none) lcolor(white)) title("Targeted Entry Restrictions against China by Date", color(black) size(5)) 
graph export "Figure3.pdf", replace

* Figure 1: Overseas Chinese Workers per 10,000 Inhabitants (2018)

* ssc install spmap

use "Chinese_workers_map.dta", clear

spmap  LS2018pc using worldcoor3.dta if countryname!="Antarctica", id(id) fcolor(Blues2) clmethod(custom) clbreaks(0 0.5 1 2  5  614)  ocolor(white ..) osize(thin ..) legend(position(7) symy(*2) symx(*2) size(7)) legorder(lohi) title("", size(10)) saving(Figure1_a, replace)
graph export "Figure1_a.pdf", replace

spmap  CP2018pc using worldcoor3.dta if countryname!="Antarctica", id(id) fcolor(Blues2) clmethod(custom) clbreaks(0 0.5 1 2  5  614)  ocolor(white ..) osize(thin ..) legend(position(7) symy(*2) symx(*2) size(7)) legorder(lohi) title("", size(10)) saving(Figure1_b, replace)
graph export "Figure1_b.pdf", replace

********************
***** APPENDiX *****
********************

use "COVID19_TRAC.dta", clear

* Table A1: Diagnostic Tests for the Proportionality Assumption

stset date, id (cowcode) failure (be_cat_1_China_carryover)
stsum

stcox contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china trade_china_gdp_2018 trade_nonchina_gdp_2018 deaths_7_day_pc, nohr vce(robust)
stphtest, log detail

* Table A2: Category 1 Entry Restrictions (Interaction with Time Added)

gen time_trade_non_china = time * trade_nonchina_gdp_2018
label var time_trade_non_china "Time * Trade with Others"

eststo clear

eststo: stcox contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china fdi_china_inward_pc_2018 trade_china_gdp_2018 trade_nonchina_gdp_2018 time_trade_non_china deaths_7_day_pc, nohr vce(robust)

esttab using "TableA2.tex", label keep(contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 fdi_china_inward_pc_2018 log_gdp log_gdp_pc trade_china_gdp_2018 trade_nonchina_gdp_2018 log_resource_pc polity2 health_2018 distcap_china time_trade_non_china deaths_7_day_pc) order(contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 fdi_china_inward_pc_2018 log_gdp log_gdp_pc trade_china_gdp_2018 trade_nonchina_gdp_2018 log_resource_pc polity2 health_2018 distcap_china time_trade_non_china deaths_7_day_pc) nonotes se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) compress nogaps nodepvars mtitles("" "" "" "" "" "") 

* Table A3: Binary Probit: Category 1 Entry Restrictions

eststo clear 
eststo: dprobit be_cat_1_China_carryover contract_workers_abroad_2018_pc migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china fdi_china_inward_pc_2018 trade_china_gdp_2018 trade_nonchina_gdp_2018 deaths_7_day_pc if date == 22001, robust
eststo: dprobit be_cat_1_China_carryover labor_services_workers_2018_pc migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china fdi_china_inward_pc_2018 trade_china_gdp_2018 trade_nonchina_gdp_2018 deaths_7_day_pc if date == 22001, robust
eststo: dprobit be_cat_1_China_carryover intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china fdi_china_inward_pc_2018 trade_china_gdp_2018 trade_nonchina_gdp_2018 deaths_7_day_pc if date == 22001, robust
eststo: dprobit be_cat_1_China_carryover contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china fdi_china_inward_pc_2018 trade_china_gdp_2018 trade_nonchina_gdp_2018 deaths_7_day_pc if date == 22001, robust

esttab using "TableA3.tex", label keep(contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 fdi_china_inward_pc_2018 log_gdp log_gdp_pc trade_china_gdp_2018 trade_nonchina_gdp_2018 log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc) order(contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 fdi_china_inward_pc_2018 log_gdp log_gdp_pc trade_china_gdp_2018 trade_nonchina_gdp_2018 log_resource_pc polity2 health_2018 distcap_china deaths_7_day_pc) nonotes se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) compress nogaps nodepvars mtitles("" "" "" "" "" "") 

* Table A4: Negative Binomial: Number of Days to Category 1 Entry Restrictions

eststo clear

eststo: nbreg days_to_category1 contract_workers_abroad_2018_pc migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china deaths_pc if date == 22001, vce(robust)
eststo: nbreg days_to_category1 labor_services_workers_2018_pc migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china deaths_pc if date == 22001, vce(robust)
eststo: nbreg days_to_category1 intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china deaths_pc if date == 22001, vce(robust)
eststo: nbreg days_to_category1 contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china deaths_pc if date == 22001, vce(robust)
eststo: nbreg days_to_category1 contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china fdi_china_inward_pc_2018 trade_china_gdp_2018 deaths_pc if date == 22001, vce(robust)
eststo: nbreg days_to_category1 contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 log_gdp log_gdp_pc log_resource_pc polity2 health_2018 distcap_china fdi_china_inward_pc_2018 trade_china_gdp_2018 trade_nonchina_gdp_2018 deaths_pc if date == 22001, vce(robust)

esttab using "TableA4.tex", label keep(contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 fdi_china_inward_pc_2018 log_gdp log_gdp_pc trade_china_gdp_2018 trade_nonchina_gdp_2018 log_resource_pc polity2 health_2018 distcap_china deaths_pc) order(contract_workers_abroad_2018_pc labor_services_workers_2018_pc intl_student_pc_china2018 migration_from_china_pc2019 migration_total2019 fdi_china_inward_pc_2018 log_gdp log_gdp_pc trade_china_gdp_2018 trade_nonchina_gdp_2018 log_resource_pc polity2 health_2018 distcap_china deaths_pc) nonotes se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) compress nogaps nodepvars mtitles("" "" "" "" "" "") 

* Table A6: Impact of Entry Restrictions on COVID-19 Confirmed Cases and Deaths

xtset cowcode date

foreach var of varlist be_cat_1_China_carryover be_cat_2_China_carryover be_cat_3_China_carryover  {
	gen L7`var' = L7.`var'
	gen L14`var' = L14.`var'
	gen L21`var' = L21.`var'
 
}

label var L7be_cat_1_China_carryover "Category 1 (t-7)"
label var L7be_cat_2_China_carryover "Category 2 (t-7)"
label var L7be_cat_3_China_carryover  "Category 3 (t-7)"

label var L14be_cat_1_China_carryover "Category 1 (t-14)"
label var L14be_cat_2_China_carryover "Category 2 (t-14)"
label var L14be_cat_3_China_carryover  "Category 3 (t-14)"

label var L21be_cat_1_China_carryover "Category 1 (t-21)"
label var L21be_cat_2_China_carryover "Category 2 (t-21)"
label var L21be_cat_3_China_carryover  "Category 3 (t-21)"


eststo clear
eststo: xi: regress confirmed_7_day_pc L7be_cat_1_China_carryover L7be_cat_2_China_carryover L7be_cat_3_China_carryover  time time_sq time_cube i.cowcode
eststo: xi: regress confirmed_7_day_pc L14be_cat_1_China_carryover L14be_cat_2_China_carryover L14be_cat_3_China_carryover  time time_sq time_cube i.cowcode

eststo: xi: regress deaths_7_day_pc L7be_cat_1_China_carryover L7be_cat_2_China_carryover L7be_cat_3_China_carryover  time time_sq time_cube i.cowcode
eststo: xi: regress deaths_7_day_pc L14be_cat_1_China_carryover L14be_cat_2_China_carryover L14be_cat_3_China_carryover  time time_sq time_cube i.cowcode

esttab using "TableA6.tex", label keep(L7be_cat_1_China_carryover L7be_cat_2_China_carryover L7be_cat_3_China_carryover  L14be_cat_1_China_carryover L14be_cat_2_China_carryover L14be_cat_3_China_carryover) order(L7be_cat_1_China_carryover L7be_cat_2_China_carryover L7be_cat_3_China_carryover  L14be_cat_1_China_carryover L14be_cat_2_China_carryover L14be_cat_3_China_carryover ) indicate("Country FE = *cow*" "Time trend = *time*") nonotes se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) compress nogaps nodepvars mtitles("" "" "" "" "" "" "" "")  

* Table A5: Entry Restrictions by Category and Monthly Passenger Volume (Jan-Mar)

duplicates drop cowcode month, force

eststo clear 
eststo: xtreg log_passenger_china be_cat_1_China_carryover be_cat_2_China_carryover be_cat_3_China_carryover, fe 
eststo: xi: xtreg log_passenger_china be_cat_1_China_carryover be_cat_2_China_carryover be_cat_3_China_carryover time time_sq time_cube, fe 
eststo: xi: xtreg log_passenger_china be_cat_1_China_carryover be_cat_2_China_carryover be_cat_3_China_carryover i.time, fe 

esttab using "TableA5.tex", label keep(be_cat_1_China_carryover be_cat_2_China_carryover be_cat_3_China_carryover be_cat_2_China_carryover be_cat_3_China_carryover ) order(be_cat_1_China_carryover  be_cat_2_China_carryover be_cat_3_China_carryover be_cat_3_China_carryover ) nonotes se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) compress nogaps nodepvars mtitles("" "" "") 